<h3>
	Menu Access Area (Access level)	
</h3>
<?php 
//print_r($menu_headings);
?>
<div class="row-fluid">
<div>
	<h4></h4>	 
	<form action="<?php echo site_url('founder/menu/grant_access')?>" method="POST">
	<div class="row-fluid">
	<div class="span3"><h4>Menu Name</h4></div>	
	<div class="span9">
	<?php 
		foreach($roles as $role){?>
		<div class="span2"><h5><?php echo $role->name?></h5></div>
		<?php }?>		
	</div></div>
	<hr />
	<div id="contentLeft">
	<ul  class="ui-sortable" style="list-style:none;margin:0;">
	<?php foreach($menu_headings as $mh){?>
		<li id="recordsArray_<?= $mh->id?>">
		<div class="row-fluid">
		<div class="span3">
		<?php echo $mh->name?>
							<!--<?php if($menu->is_heading == 0){ ?>
		<a id="heading_<?php echo $mh->id?>" href="#" class="tooltips" title="<?php echo  $mh->url?>" ><i class="<?php echo $menu->icon?>"></i> <?php echo $menu->name ?></a>
		<?php } else { echo '<b>'.$menu->name.'</b>'; }?>-->
		<?php 
		//$child_menus = $this->menu_model->get_child_menu($menu->id);
		//if(isset($child_menus)){
		//	echo '<br />';		
		//foreach($child_menus as $child_menu){
		//	?>			
			&nbsp;&nbsp;&nbsp;<a href="#" class="tooltips" title="<?php echo $child_menu->url?>" ><i class="<?php echo $child_menu->icon?>"></i> <?php echo $child_menu->name ?></a>
		<br />
		<?php//	 }}
		?>
		</div>
		<div class="span9">
			<?php
			/*if($menu->is_heading == 0){	*/			
			
			foreach($roles as $role){?>
			<div class="span2">
			<?php 
			$check_id = $menu->id.$role->id;
			$checked = null;
			foreach($access as $acc){
				if($acc->menu_id.$acc->group_id == $check_id ){
					$checked= ' checked="checked"';
			break;
				}
			}
			?>
			<input type="checkbox" value="<?php echo $check_id?>" name="menu_access[<?php echo $menu->id?>][<?php echo $role->id?>]" <?php echo $checked;?> />
			<?php foreach($child_menus as $cm){ ?>
			<br />
			<?php 
			$check_id = $cm->id.$role->id;
			$checked = null;
			foreach($access as $ac){
				if($ac->menu_id.$ac->group_id == $check_id ){
					$checked= ' checked="checked"';
			break;
				}
			}			
			?>
			<input type="checkbox" value="" name="menu_access[<?php echo $cm->id?>][<?php echo $role->id?>]" <?php echo $checked;?> />			
			<?php }?>			
			</div>			
			<?php }?>			
		</div>		
		</div>
		</li>
	<?php
	}
	?>
	</ul>
	</div>
	<hr />
	<input type="submit" class="btn btn-danger pull-right" value="save all access"/>
	</form>
	
</div>
</div>
<hr />
<div class="row-fluid">
<div class="span4">
<h4>Create Heading</h4>
<hr />
<input  type="text" id="heading_name" placeholder="Heading Name"/>
<input  type="text" id="heading_icon" placeholder="Heading Icon"/>
<input  type="button" class="btn" value="Create heading" id="create_heading" onclick="create_heading()"/>
</div>
<div class="span4">
<form>
  <fieldset >
   <h4>Create Menu</h4>
   <hr />
    <select class="chzn-select" id="">
	<option value=""> Select Heading</option>
	</select>
   <select class="chzn-select" id="parent">
		<option value="">Select Parent</option>	
		<?php foreach($menu_items as $parent){?>
		<option value="<?php echo $parent->id?>"><?php echo $parent->name?></option>
		<?php }?>
	</select>
    <input type="text" placeholder="Menu Name" id="name">
    <input type="text" placeholder="controller/function" id="url">	
    <input type="text" placeholder="glyphicons  ex.icon-user" id="icon">
	<label>
    <button type="button" class="btn btn-success" onclick="create_menu()">Create Menu</button>
	</label>
  </fieldset>
</form>
</div>

<div class="span4">
	<h4>Edit</h4>
	<hr />
	<select class="chzn-select" name="edit_menu" id="edit_menu">
		<option></option>
	</select>
	<div class="edit_menu">
	<label>
	<input type="button" value="Update" class="btn btn-info"/>
	</label>
	</div>
</div>
</div>

<script type="text/javascript">
$(document).ready(function(e) {
	// drag n drop	
	jQuery(function() {
		//alert("asdds");
		jQuery("#contentLeft ul").sortable({   opacity: 0.6, cursor: 'move',  update: function() {			
			var order = jQuery(this).sortable("serialize") + '&action=updateRecordsListings'; 
			//alert(order);
			jQuery.post("<?= site_url('founder/menu/sorting');?>", order, function(theResponse){
				alert(theResponse);
			}); 															 
		}								  
		});
		});});



<!--

function create_menu(){	
var name = $('#name').val();
var urls = $('#url').val();
var parent = $('#parent').val();
var icon = $('#icon').val();
	//alert(name);
	$.post('<?= site_url('founder/menu/create_menu');?>',{name : name , urls : urls, parents : parent, icon:icon  }, function(data) {		
			 alert(data);
			  $('#parent').val('');
			 $('#name').val('');
			  $('#url').val('');
			location.reload();
			
});

}

/*Create heading*/
function create_heading(){	
var name = $('#heading_name').val();
var icon = $('#heading_icon').val();
	//alert(name);
	$.post('<?= site_url('founder/menu/create_heading');?>',{name : name , icon:icon }, function(data) {		
				 alert(data);
				$('#heading_name').val('');
				$('#heading_icon').val('');
				location.reload();
			});
			}

function access(role_id,menu_id){
	
	//document.getElementById(role_id);
	if(this.checked) {
	alert(role_id);	
		}
	else{
	alert(menu_id);	
	}
	
	
	/*$.post('<?= site_url('');?>',{name : name , urls : urls  }, function(data) {		
			 $('#name').val('');
			  $('#url').val('');
			location.reload();
			//alert(data);
});*/
}
//-->
</script>